package com.cn.steam.iam.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.steam.foundation.common.model.exception.BadRequestException;
import com.cn.steam.iam.mapper.iam.IamRoleMapper;
import com.cn.steam.iam.model.po.IamRole;
import com.cn.steam.iam.model.vo.IamRoleVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author zjm
 * @date 2021/05/07
 */
@Service
public class IamRoleProfileService extends ServiceImpl<IamRoleMapper, IamRole> {

    public String addIamRoleMapping(IamRole iamRole){
        Date currTime = new Date();
        iamRole.setCreateTime(currTime);
        if(null == iamRole.getRoleId()){
            getBaseMapper().addImaRole(iamRole);
            return iamRole.getRoleId();
        }
        IamRole hasIamRole = getBaseMapper().selectById(iamRole.getRoleId());

        if(hasIamRole != null){
            throw new BadRequestException("the role already exists");
        }

        getBaseMapper().insert(iamRole);
        return iamRole.getRoleId();
    }

    public void deleteById(String roleId){
        getBaseMapper().deleteById(roleId);
    }

    public List<IamRole> qryIamRoleList(IamRoleVo iamRoleVo){
        return getBaseMapper().qryIamRoleList(iamRoleVo);
    }
}
